using System;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Web;

using System.Collections;
using CE.Database;
using CE.Configuration;
/// <summary>
/// Summary description for General
/// </summary>
/// 
namespace CE.Global
{
    public class General
    {
        public static string UserId = "UserId";
        public static string FB_UserId = "FB_UserId";
        public static string FB_UserProfileUrl = "FB_UserProfileUrl";
        public static string UserProfileAndContactComplete = "IsProfileContactComplete";

        public static string UserTypeId = "UserTypeId";
        public static string UserEmail = "UserEmail";
        public static string UserGender = "UserGender";
        public static string UserDOB = "UserDOB";
        public static string UserPhoneNo = "UserPhone";
        public static string UserName = "UserName";
        public static string UserICNumber = "UserICNumber";
        public static string RequestUrl = "RequestUrl";
        public static string StartTime = "StartTime";
        public static string Guest = "Guest";
        public static string LoginHistoryId = "LoginHistoryId";
        public static string LastLoginTime = "LastLoginTime";
        public static string CI_RED = "CI_RED";
        public static string SecurityCheckWord = "Salt";

        //Agent
        public static string AgentId = "AgentId";
        public static string AgentName = "AgentName";

        //Car Insurance Session
        public static string CarServiceName = "Car Insurance";
        public static string CarId = "CarId";
        public static string CarPolicyId = "CarPolicyId";
        public static string CarResultId = "CarResultId";
        public static string IsCarRestoreResult = "IsCarRestoreResult";
        public static string CarMoreDetailId = "CarMoreDetailId";
        public static string CarClaimHistoryId = "CarClaimHistoryId";
        public static string CvvId = "CvvId";
        public static string IsCarDetailChange = "IsCarDetailChange";

        //Home Loan
        public static string HFServiceName = "Home Loans";
        public static string HFId = "HFID";
        public static string HFPersonnelId = "HFPersonnelID";
        public static string HFResultId = "HFResultId";
        public static string HFPropertyId = "HFPropertyId";
        public static string HFUserName = "HFUserName";
        public static string HFPhoneNo = "HFPhoneNo";
        public static string HFEmail = "HFEmail";
        //New from 18 Jan 2011
        public static string HLServiceName = "Home Loans";
        public static string HLId = "HLId";
        public static string HLPersonnelId = "HLPersonnelId";
        public static string HLResultId = "HLResultId";
        public static string HLPropertyId = "HLPropertyId";
        public static string HLUserName = "HLUserName";
        public static string HLPhoneNo = "HLPhoneNo";
        public static string HLEmail = "HLEmail";


        //Personal Loan
        public static string PLServiceName = "Personal Loans";
        public static string PLId = "PLID";
        public static string PLUserName = "PLUserName";
        public static string PLPhoneNo = "PLPhoneNo";
        public static string PLEmail = "PLEmail";
        public static string PLPersonnelId = "PLPersonnelID";
        public static string PLResultId = "PLResultId";

        public static string PLEmpId = "PLAREID";

        //Personal Accident
        public static string PAServiceName = "Personal Accident";
        public static string PAId = "PAID";
        public static string PAUserName = "PAUserName";
        public static string PAPhoneNo = "PAPhoneNo";
        public static string PAEmail = "PAEmail";
        public static string PAPersonnelId = "PAPersonnelID";
        public static string PAResultId = "PAResultId";
        public static string PAProposalId = "PAProposalId";

        //Travel Insurance
        public static string TAServiceName = "Travel Insurance";
        public static string TAId = "TAID";
        public static string TAUserName = "TAUserName";
        public static string TAPhoneNo = "TAPhoneNo";
        public static string TAEmail = "TAEmail";
        public static string TAPersonnelId = "TAPersonnelID";
        public static string TAResultId = "TAResultId";
        public static string TACustomerAge = "TACustomerAge";

        //Provider Session
        public static string ProviderCompanyId = "ProviderCompanyId";
        public static string ProviderProfileFirstTime = "IsProviderProfileFirstTime";
        public static string ProviderUserTypeId = "ProviderUserTypeId";
        public static string ProviderUserAccessLevel = "ProviderUserAccessLevel";

        //CreditCard Compare Request
        public static string CCServiceName = "Credit Cards";
        public static string CCARId = "CCARID";
        public static string CCRequestStatus = "CCRequestStatus";
        public static string CCId = "CCID";
        public static string CCRFullName = "CCRFullName";
        public static string CCRMobileNo = "CCRMobileNo";
        public static string CCREmail = "CCREmail";
        public static string CCPersonnelId = "CCPERSONNELID";


        //View Details ID
        public static string ViewedDetailsId = "ViwedDetailsId";

        //DownLoad Proposal
        public static string RefId = "RefId";
        public static string InsType = "InsType";
        //Feed Back Receiver
        public General()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static DataTable GetComboItem(string keyName, bool status)
        {
            DataTable _dt = null;
            try
            {
                MyDatabase _db = new MyDatabase();

                string _keyValue = MyConfigurationManager.GetAppSettingValue(keyName);
                string[] _keyValueList = _keyValue.Split(',');

                string _sqlstatement = "SELECT " + _keyValueList[2] + ", " + _keyValueList[1] + " FROM " + _keyValueList[0];
                string _sqlwhere = "";

                if (status)
                {
                    _sqlwhere = " Where [Status] = 1 ";
                    _sqlstatement += _sqlwhere;
                }

                if (_keyValueList[0] == "tblCountryInfo")
                {
                    _sqlstatement += " Order By " + _keyValueList[2];
                }
                else
                {
                    _sqlstatement += " Order By " + _keyValueList[1];
                }
                _dt = _db.GetDataTable(_sqlstatement);
            }
            catch (Exception Ex)
            {
            }

            return _dt;
        }
        
        public static DataTable GetComboItem(string keyName, string OrderBy, bool status)
        {
            DataTable _dt = null;
            try
            {
                MyDatabase _db = new MyDatabase();

                string _keyValue = MyConfigurationManager.GetAppSettingValue(keyName);
                string[] _keyValueList = _keyValue.Split(',');

                string _sqlstatement = "SELECT " + _keyValueList[2] + ", " + _keyValueList[1] + " FROM " + _keyValueList[0];
                string _sqlwhere = "";

                if (status)
                {
                    _sqlwhere = " Where [Status] = 1 ";
                    _sqlstatement += _sqlwhere;
                }

                if (OrderBy != "")
                {
                    _sqlstatement += " Order by " + OrderBy;
                }

                _dt = _db.GetDataTable(_sqlstatement);
            }
            catch (Exception Ex)
            {
            }

            return _dt;
        }
        
        public static DataTable GetComboItem(string keyName, string whereKey, string whereId, bool status)
        {
            DataTable _dt = null;
            try
            {
                MyDatabase _db = new MyDatabase();

                string _keyValue = MyConfigurationManager.GetAppSettingValue(keyName);
                string[] _keyValueList = _keyValue.Split(',');

                string _sqlstatement = "SELECT " + _keyValueList[2] + ", " + _keyValueList[1] + " FROM " + _keyValueList[0];
                _sqlstatement += " WHERE " + whereKey + " = " + whereId;
                string _sqlwhere = "";

                if (status)
                {
                    _sqlwhere = " AND [Status] = 1;";
                    _sqlstatement += _sqlwhere;
                }

                _dt = _db.GetDataTable(_sqlstatement);
            }
            catch (Exception Ex)
            {
            }

            return _dt;
        }

        public static Int64 IsExistId(string tblName, string filterFieldName, Int64 filterValue, bool status)
        {
            MyDatabase _db = new MyDatabase();
            string _sql = "Select " + filterFieldName + " from " + tblName + " WHERE " + filterFieldName + " = @filterValue";

            //SqlParameter[] _sqlpara = new SqlParameter();

            //object _result = _db.ExecuteScalarSqlStatement(_sql, _sqlpara);

            return 1;
        }

        public static Hashtable GetDayList(int sMonth, int sYear)
        {
            int _daycount = 31;
            bool isLeapYear = DateTime.IsLeapYear(sYear);

            if (isLeapYear && sMonth == 2)
            {
                _daycount = 29;
            }
            else if (sMonth == 2)
            {
                _daycount = 28;
            }
            else if (sMonth == 4 || sMonth == 6 || sMonth == 9 || sMonth == 11)
            {
                _daycount = 30;
            }
            else
            {
                _daycount = 31;
            }
            Hashtable ht_day = new Hashtable(_daycount);
            for (int i = _daycount; i >= 1; i--)
            {
                ht_day.Add(i, i);
            }

            return ht_day;
        }

        public static Hashtable GetDOBYearList()
        {
            int _sYear = Convert.ToInt32(MyConfigurationManager.GetAppSettingValue("StartDOBYear"));
            int _eYear = Convert.ToInt32(MyConfigurationManager.GetAppSettingValue("EndDOBYear"));
            int _yCount = _eYear - _sYear;
            Hashtable ht_year = new Hashtable(_yCount);

            for (int i = _sYear; i <= _eYear; i++)
            {
                ht_year.Add(i, i);
            }

            return ht_year;
        }

        public static Hashtable GetMonthList(string format)
        {
            Hashtable ht_month = new Hashtable(12);
            DateTime dt = new DateTime(2009, 1, 1);
            for (int i = 1; i <= 12; i++)
            {
                string monthName = string.Format("{0:" + format + "}", dt.AddMonths(i - 1));
                ht_month.Add(i, monthName);
            }
            return ht_month;
        }

        public static string ClearScriptTag(string strSource)
        {
            String sourcestring = strSource;
            String matchpattern = @"<script[^>]*?.*?</script>";
            //String matchpattern = @"<script\s[^>]*?</script>";
            //String matchpattern = @"<script\s[^>]*>(?:(?!</script>).)*?\r\n(?:function blabla\(\)|blabla\(\);)(?:(?!</script>).)*?</script>";
            String replacementpattern = @"";
            String result = Regex.Replace(sourcestring, matchpattern, replacementpattern, RegexOptions.IgnoreCase);
            return result;
        }

        public static bool IsInteger(String strNumber)
        {
            Regex objNotNaturalPattern = new Regex("[^0-9]");
            Regex objNaturalPattern = new Regex("[0-9][0-9]*");

            return !objNotNaturalPattern.IsMatch(strNumber) &&
            objNaturalPattern.IsMatch(strNumber);
        }

        public static string GetRefNumber(string strExceptType, string PostedDate, string ID)
        {
            String _result = "";
            String _refnumber = "";
            MyDatabase _db = new MyDatabase();
            String _strSql = "SELECT CONVERT(VARCHAR,(CONVERT(DATETIME,'" + PostedDate + "',103)),112)";
            _result = _db.ExecuteScalarSqlStatement(_strSql).ToString();
            _refnumber = strExceptType + _result + ID;
            return _refnumber;
        }

        public static string GetRefNumber(Int64 FirstId)
        {
            string _vallasttwo = "";
            string _valfirstchar = "";
            string _valsecondchar = "";
            string _valremaining = "";
            string _result = "";
            Int64 _firstId = FirstId;
            if (_firstId.ToString().Length >= 2)
            {
                _valremaining = _firstId.ToString().Substring(0, _firstId.ToString().Length - 2);
                _vallasttwo = _firstId.ToString().Substring(_firstId.ToString().Length - 2, 2);
                _valfirstchar = _vallasttwo.Substring(0, 1);
                _valsecondchar = _vallasttwo.Substring(1, 1);
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _valsecondchar = NumberToChar(Convert.ToInt32(_valsecondchar));
                _result = _valremaining + "" + _valfirstchar + "" + _valsecondchar;
            }
            else if (_firstId.ToString().Length == 1)
            {
                _valfirstchar = _firstId.ToString();
                _valfirstchar = NumberToChar(Convert.ToInt32(_valfirstchar));
                _result = _valfirstchar;
            }
          
            return _result;
        }

        public static string NumberToChar(int id)
        {
            string C = "";
            if (id == 1)
                C = "A";
            else if (id == 2)
                C = "B";
            else if (id == 3)
                C = "C";
            else if (id == 4)
                C = "D";
            else if (id == 5)
                C = "E";
            else if (id == 6)
                C = "F";
            else if (id == 7)
                C = "G";
            else if (id == 8)
                C = "H";
            else if (id == 9)
                C = "I";
            else if (id == 0)
                C = "J";
            return C;
        }

        public static Int64 GetProductId(string RefNumber, string ProductType)
        {
            string _result = "";
            string _firstId = "";
            if (ProductType == "CI")
            {
                _firstId = RefNumber.ToString().Substring(1, RefNumber.ToString().Length - 1);
            }
            else
            {
                _firstId = RefNumber.ToString().Substring(3, RefNumber.ToString().Length - 3);
            }
            char[] letters = _firstId.ToCharArray();
            for (int i = 0; i < letters.Length; i++)
            {
                _result += CharToNumber(letters[i].ToString());
            }
            return Convert.ToInt64(_result.ToString());
        }

        public static string CharToNumber(string ltr)
        {
            string N = ltr.ToString();
            if (ltr == "A")
                N = "1";
            else if (ltr == "B")
                N = "2";
            else if (ltr == "C")
                N = "3";
            else if (ltr == "D")
                N = "4";
            else if (ltr == "E")
                N = "5";
            else if (ltr == "F")
                N = "6";
            else if (ltr == "G")
                N = "7";
            else if (ltr == "H")
                N = "8";
            else if (ltr == "I")
                N = "9";
            else if (ltr == "J")
                N = "0";
            return N;
        }

        public static void ClearAllSession(System.Web.UI.Page PageSession, string strExceptType)
        {
            #region Comment
            //string strUserId = string.Empty;
            //string strUserTypeId = string.Empty;
            //string strUserEmail = string.Empty;
            //string strUserPhoneNo = string.Empty;
            //string strUserName = string.Empty;

            //if (PageSession.Session[UserId] != null) strUserId = PageSession.Session[UserId].ToString();
            //if (PageSession.Session[UserTypeId] != null) strUserId = PageSession.Session[UserTypeId].ToString();
            //if (PageSession.Session[UserEmail] != null) strUserId = PageSession.Session[UserEmail].ToString();
            //if (PageSession.Session[UserPhoneNo] != null) strUserId = PageSession.Session[UserPhoneNo].ToString();
            //if (PageSession.Session[UserName] != null) strUserId = PageSession.Session[UserName].ToString();

            //PageSession.Session.Clear();
            //PageSession.Session.Abandon();

            //PageSession.Session[UserId] = strUserId;
            //PageSession.Session[UserTypeId] = strUserTypeId;
            //PageSession.Session[UserEmail] = strUserEmail;
            //PageSession.Session[UserPhoneNo] = strUserPhoneNo;
            //PageSession.Session[UserName] = strUserName;

            //PageSession.Session["UserId"] = "UserId";
            //PageSession.Session["UserTypeId"] = "UserTypeId";
            //PageSession.Session["UserEmail"] = "UserEmail";
            //PageSession.Session["UserPhoneNo"] = "UserPhone";
            //PageSession.Session["UserName"] = "UserName";
            //PageSession.Session["UserICNumber"] = "UserICNumber";
            //PageSession.Session["RequestUrl"] = "RequestUrl";
            //PageSession.Session["StartTime"] = "StartTime";
            //PageSession.Session["Guest"] = "Guest";
            //PageSession.Session["LoginHistoryId"] = "LoginHistoryId";
            //Car Insurance Session
            #endregion

            PageSession.Session["salt"] = null;
            PageSession.Session["ImageCount"] = null;

            if (strExceptType != "CI")
            {
                PageSession.Session["CarId"] = null;
                PageSession.Session["CarPolicyId"] = null;
                PageSession.Session["CarResultId"] = null;
                PageSession.Session["CarMoreDetailId"] = null;
                PageSession.Session["CarClaimHistoryId"] = null;
                PageSession.Session["CvvId"] = null;
                PageSession.Session["IsCarRestoreResult"] = null;
            }

            //Home Loan
            if (strExceptType != "HF")
            {
                PageSession.Session["HFId"] = null;
                PageSession.Session["HFPersonnelId"] = null;
                PageSession.Session["HFResultId"] = null;
                PageSession.Session["HFPropertyId"] = null;
                PageSession.Session["HFUserName"] = null;
                PageSession.Session["HFPhoneNo"] = null;
                PageSession.Session["HFEmail"] = null;
            }
            //New on 18 Jan 2011
            //Home Loan
            if (strExceptType != "HL")
            {
                PageSession.Session["HLId"] = null;
                PageSession.Session["HLPersonnelId"] = null;
                PageSession.Session["HLResultId"] = null;
                PageSession.Session["HLPropertyId"] = null;
                PageSession.Session["HLUserName"] = null;
                PageSession.Session["HLPhoneNo"] = null;
                PageSession.Session["HLEmail"] = null;
            }

            //Personal Loan
            if (strExceptType != "PL")
            {
                PageSession.Session["PLId"] = null;
                PageSession.Session["PLUserName"] = null;
                PageSession.Session["PLPhoneNo"] = null;
                PageSession.Session["PLEmail"] = null;
                PageSession.Session["PLPersonnelId"] = null;
                PageSession.Session["PLResultId"] = null;
            }

            //Personal Accident
            if (strExceptType != "PA")
            {
                PageSession.Session["PAId"] = null;
                PageSession.Session["PAUserName"] = null;
                PageSession.Session["PAPhoneNo"] = null;
                PageSession.Session["PAEmail"] = null;
                PageSession.Session["PAPersonnelId"] = null;
                PageSession.Session["PAResultId"] = null;
                PageSession.Session["PAProposalId"] = null;
            }

            //Travel Insurance
            if (strExceptType != "TA")
            {
                PageSession.Session["TAId"] = null;
                PageSession.Session["TAUserName"] = null;
                PageSession.Session["TAPhoneNo"] = null;
                PageSession.Session["TAEmail"] = null;
                PageSession.Session["TAPersonnelId"] = null;
                PageSession.Session["TAResultId"] = null;
                PageSession.Session["TACustomerAge"] = null;
            }

            //Provider Session
            //if (strExceptType != "PV")
            //{
            //    PageSession.Session["ProviderCompanyId"] = null;
            //}

            //if (strExceptType != "GT")
            //{
            //    PageSession.Session["Guest"] = null;
            //}
            //CreditCard Compare Request
            if (strExceptType != "CC")
            {
                PageSession.Session["CCARId"] = null;
                PageSession.Session["CCRequestStatus"] = null;
                PageSession.Session["CCId"] = null;
                PageSession.Session["CCRFullName"] = null;
                PageSession.Session["CCRMobileNo"] = null;
                PageSession.Session["CCREmail"] = null;
                PageSession.Session["CCPersonnelId"] = null;
            }

            if (strExceptType == "LOGOUT")
            {
                ClearUserLoginCached(PageSession);
                PageSession.Session["UserId"] = null;
                PageSession.Session["UserTypeId"] = null;
                PageSession.Session["UserEmail"] = null;
                PageSession.Session["UserPhoneNo"] = null;
                PageSession.Session["UserName"] = null;

                PageSession.Session["UserICNumber"] = null;
                PageSession.Session["RequestUrl"] = null;
                PageSession.Session["StartTime"] = null;
                //PageSession.Session["Guest"] = null;
                PageSession.Session["LoginHistoryId"] = null;
                PageSession.Session["LastLoginTime"] = null;
                PageSession.Session["ProviderCompanyId"] = null;
                PageSession.Session["IsProfileContactComplete"] = null;
                PageSession.Session["ProviderUserTypeId"] = null;
                PageSession.Session["ProviderUserAccessLevel"] = null;

                PageSession.Session["AgentId"] = null;
                PageSession.Session["AgentName"] = null;
                
            }
        }

        public static void CreateUpdateUserLoginCached(System.Web.UI.Page thisPage)
        {
            string sKey = CE.Configuration.MyConfigurationManager.GetAppSettingValue("UserCacheName");
            sKey += Convert.ToString(thisPage.Session[UserId].ToString());
            // Accessing the Cache Item extends the Sliding Expiration automatically
            if (thisPage.Cache[sKey] != null)
            {
                string sUser = thisPage.Cache[sKey].ToString();
            }
            else
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, thisPage.Session.Timeout, 0, 0);
                thisPage.Cache.Insert(sKey, thisPage.Session[UserId].ToString(), null, DateTime.MaxValue, SessTimeOut,
                   System.Web.Caching.CacheItemPriority.NotRemovable, null);
            }
        }

        public static bool ClearUserLoginCached(System.Web.UI.Page thisPage)
        {
            bool _retValue = false;
            string sKey = CE.Configuration.MyConfigurationManager.GetAppSettingValue("UserCacheName");
            sKey += thisPage.Session[UserId].ToString();

            if (thisPage.Cache[sKey] == null)
            {
                _retValue = true;
            }
            else
            {
                thisPage.Cache.Remove(sKey);
                _retValue = true;
            }

            return _retValue;
        }


        public static DataTable GetProviderMainPage(Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderMainPagesSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            return _dt;
        }

        public static Int64 GetProviderMainPageAccess(Int64 ProviderCompanyId, Int64 RefCEUserId, string CXPageName)
        {
            Int64 _result = 0;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderUserAccessMainPagesSelectItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@RefCEUserId", RefCEUserId);
            _spara.Add("@CXPageName", CXPageName);
            _result = _db.ExecuteSP(_spName, _spara);

            return _result;
        }

        public static Int64 GetProviderSubPageAccess(Int64 ProviderCompanyId, Int64 RefCEUserId, string CXSubPageName)
        {
            Int64 _result = 0;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderUserAccessSubPagesSelectItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@RefCEUserId", RefCEUserId);
            _spara.Add("@CXSubPageName", CXSubPageName);
            _result = _db.ExecuteSP(_spName, _spara);

            return _result;
        }

        public static Int64 CheckProviderUserType(Int64 ProviderCompanyId, Int64 RefCEUserId)
        {
            Int64 _result = 0;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderUserTypeSelectItemByUser";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CEID", RefCEUserId);
            _result = _db.ExecuteSP(_spName, _spara);

            return _result;
        }

        public static DataSet RemoveRow(DataTable dt, Int16 rowIndex)
        {
            try
            {
                DataSet dsTemp = new DataSet();
                DataTable dtTemp = dt;
                dtTemp.Rows[rowIndex].Delete();
                dtTemp.AcceptChanges();
                dsTemp.Tables.Add(dtTemp.Copy());
                dsTemp.Tables[0].AcceptChanges();
                return dsTemp;
            }
            catch (Exception ex)
            {
                DataSet dsTemp = new DataSet();
                return dsTemp = null;
            }
        }

        public static bool isMobileBrowser()
        {
            //GETS THE CURRENT USER CONTEXT
            HttpContext context = HttpContext.Current;

            //FIRST TRY BUILT IN ASP.NT CHECK
            if (context.Request.Browser.IsMobileDevice)
            {
                return true;
            }
            //THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
            if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
            {
                return true;
            }
            //THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
            if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
                context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap"))
            {
                return true;
            }
            //AND FINALLY CHECK THE HTTP_USER_AGENT 
            //HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
            if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
            {
                //Create a list of all mobile types
                string[] mobiles =
                    new[]
                {
                    "midp", "j2me", "avant", "docomo", 
                    "novarra", "palmos", "palmsource", 
                    "240x320", "opwv", "chtml",
                    "pda", "windows ce", "mmp/", 
                    "blackberry", "mib/", "symbian", 
                    "wireless", "nokia", "hand", "mobi",
                    "phone", "cdm", "up.b", "audio", 
                    "SIE-", "SEC-", "samsung", "HTC", 
                    "mot-", "mitsu", "sagem", "sony"
                    , "alcatel", "lg", "eric", "vx", 
                    "NEC", "philips", "mmm", "xx", 
                    "panasonic", "sharp", "wap", "sch",
                    "rover", "pocket", "benq", "java", 
                    "pt", "pg", "vox", "amoi", 
                    "bird", "compal", "kg", "voda",
                    "sany", "kdd", "dbt", "sendo", 
                    "sgh", "gradi", "jb", "dddi", 
                    "moto", "iphone"
                };

                //Loop through each item in the list created above 
                //and check if the header contains that text
                foreach (string s in mobiles)
                {
                    if (context.Request.ServerVariables["HTTP_USER_AGENT"].ToLower().Contains(s.ToLower()))
                    {
                        return true;
                    }
                }
            }

            return false;
        }

        public static DateTime GetUTCDateTime()
        {
            DateTime _CurrentDateTime = DateTime.UtcNow.AddHours(8);
            return _CurrentDateTime;
        }
    }

    public enum CEUserType
    {
        SiteAdmin = 100,
        SiteUser = 200,
        Provider = 300,
        Customer = 400,
        Advertiser = 500,
        Guest = 600
    }


}
